var $ = jQuery;

function openStream(url_in) {
	sendCometAjax(url_in, null, null, function(result) {
		var rtnWebBlog = requestWebBlog(url_in);
		$("#WBWall").prepend(rtnWebBlog);
	});
}

/**
 * @param url_in
 * @param data_in
 * @param errFunc
 * @param sucFunc
 */
function sendCometAjax(url_in, data_in, errFunc, sucFunc) {
	$.ajax({
		url : url_in,
		type : 'POST',
		datatype : 'text',
		data : data_in,
		timeout : 10000,
		error : function(errMsg) {
			// alert(errMsg[0]);
			// alert('Error loading PHP document');

			if (errFunc != null) {
				errFunc(errMsg);
			}
		},

		success : function(result) {
			// alert(result);
			sucFunc();
		}

	});
}

function requestWebBlog(url_in) {

	sendCometAjax(url_in, {
		method : "requestWebBlog"
	}, function(errMsg) {
		alert(errMsg);
	}, function(newWB) {
		return newWB;
	});
}